<template>
  <el-form :inline="true" :disabled="!isForbidden" class="demo-form-inline my-from">
    <el-form-item label="一级分类">
      <el-select :value="category1Id" placeholder="请选择一级分类" @change="getCateGory2List">
        <el-option v-for="c1 in category1List" :key="c1.id" :label="c1.name" :value="c1.id"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="二级分类">
      <el-select :value="category2Id" placeholder="请选择二级分类" @change="getCateGory3List">
        <el-option v-for="c2 in category2List" :key="c2.id" :label="c2.name" :value="c2.id"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="三级分类">
      <el-select :value="category3Id" placeholder="请选择三级分类" @change="SAVE_CATEGORY3_ID">
        <el-option v-for="c3 in category3List" :key="c3.id" :label="c3.name" :value="c3.id"></el-option>
      </el-select>
    </el-form-item>
  </el-form>
</template>

<script>
import { mapActions, mapMutations, mapState } from 'vuex'
export default {
  name: 'CategorySelector',

  props: {
    isForbidden: {
      tyoe: Boolean,
      require: true,
      default: true
    }
  },

  mounted() {
    this.getCateGory1List()
  },
  computed: {
    ...mapState('category', ['category1List', 'category2List', 'category3List', 'category1Id', 'category2Id', 'category3Id'])
  },
  beforeDestroy() {
    this.RESET()
  },
  methods: {
    ...mapActions('category', ['getCateGory1List', 'getCateGory2List', 'getCateGory3List']),
    ...mapMutations('category', ['SAVE_CATEGORY3_ID', 'RESET'])
  }
}
</script>

<style lang="scss" scoped>
.my-from {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>